<?php

namespace App\Http\Controllers\Network;

use App\Http\Controllers\Controller;
use App\Http\Requests\Network\Service\NetworkQuery;
use App\Repositories\NetworkRepository;
use App\Repositories\UserLogRepository;
use Illuminate\Support\Facades\Auth;

class ServiceController extends Controller
{
    protected $networkRepository;
    protected $userLogRepository;

    /**
     * NetworksController constructor.
     * @param NetworkRepository $networkRepository
     * @param UserLogRepository $userLogRepository
     */
    public function __construct(
        NetworkRepository $networkRepository,
        UserLogRepository $userLogRepository
    )
    {
        $this->networkRepository = $networkRepository;
        $this->userLogRepository = $userLogRepository;
    }

    /**
     * 获取关联站点
     *
     * Date: 2018/06/12
     * @author Tenny
     * @param NetworkQuery $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function relationStation(NetworkQuery $request)
    {
        $limit = $request->get('paginate', 15);
        $service_name = $request->get('service_name', false);
        if ($service_name === null) {
            $service_name = false;
        }
        $admins = Auth::guard('network')->user();
        $network_id = $admins->network_id;
        $networks = $this->networkRepository->getRelationStationLists($network_id, $limit, $service_name);
        return success($networks);
    }
}
